﻿using BestHTTP;
using System;
using UnityEngine;

namespace ZWFrameWork
{

    public class HttpManager : HttpBase
    {
        public override void SendOTP(string mobile, string type, OnRequestFinishedDelegate callback = null)
        {
            var body = "{\"mobile\" : \"" + mobile + "\", \"type\" : \"" + type + "\"}";
            var request = new HTTPRequest(new Uri(""), HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.Log(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }

        public override void Payment(string coin, string userid, string orderType,
            OnRequestFinishedDelegate callback = null)
        {
            var body = "{\"userId\" : \"" + userid + "\", \"amount\" : \"" + coin + "\", \"orderType\" : \"" +
                       orderType +
                       "\"}";
            var request = new HTTPRequest(new Uri("r"), HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.Log(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }

        public override void PaymentOrderList(string userid, string size, OnRequestFinishedDelegate callback = null)
        {
            var body = "{\"userid\" : \"" + userid + "\", \"size\" : \"" + size + "\"}";
            var request = new HTTPRequest(new Uri(""), HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.Log(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }

        public override void GetLoginGilt(string userid, OnRequestFinishedDelegate callback = null)
        {
            var body = "{\"userid\" : \"" + userid + "\"}";
            var request = new HTTPRequest(new Uri(""), HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.Log(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }

        public override void SendQianDao(string userid, OnRequestFinishedDelegate callback = null)
        {
            var body = "{\"userid\" : \"" + userid + "\"}";
            var request = new HTTPRequest(new Uri(""), HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.Log(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }

        /// <summary>
        /// Post获取服务数据
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="postUrl"></param>
        /// <param name="callback"></param>
        public override void SendHttpPost(string body, string postUrl, OnRequestFinishedDelegate callback = null)
        {
            Debug.LogError("userid=======" + body + "==========uspostUrl" + postUrl);

            var request = new HTTPRequest(new Uri(postUrl), HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.LogError(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }

        public override void CheckLoginBefore(string lang, string mccMnc, bool isOpenVpn, bool isOpenFlight,
            string timezone, string adJustId, string ip, string adgroup, OnRequestFinishedDelegate callback = null)
        {
            var body = "{\"lang\" : \"" + lang + "\", \"mccMnc\" : \"" + mccMnc + "\",\"isOpenVpn\":\"" + isOpenVpn +
                       "\",\"isOpenFlight\":\"" + isOpenFlight + "\",\"timezone\":\"" + timezone +
                       "\",\"adJustId\":\"" +
                       adJustId + "\",\"ip\":\"" + ip + "\",\"adgroup\":\"" + adgroup + "\"}";
            var request = new HTTPRequest(new Uri("https://front.magiccubegamestudio.online/user/checkLoginBefore"),
                HTTPMethods.Post, callback);
            request.SetHeader("Content-Type", "application/json; charset=UTF-8");
            Debug.Log(body);
            request.RawData = System.Text.Encoding.UTF8.GetBytes(body);
            request.Send();
        }
    }
}